package com.salary.system;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public abstract class Employee {
    private String name;
    private String empId;
    private String department;
    private LocalDate hireDate;

    public Employee(String name, String empId, String department, LocalDate hireDate) {
        if (name == null || name.trim().isEmpty()) {
            throw new IllegalParameterException("姓名不能为空");
        }
        if (empId == null || empId.trim().isEmpty()) {
            throw new IllegalParameterException("工号不能为空");
        }
        if (department == null || department.trim().isEmpty()) {
            throw new IllegalParameterException("部门不能为空");
        }
        this.name = name;
        this.empId = empId;
        this.department = department;
        this.hireDate = hireDate;
    }

    public abstract double calculateSalary() throws InvalidWorkHoursException;

    public String generatePaySlip() throws InvalidWorkHoursException {
        double salary = calculateSalary();
        String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return "===== 工资条（生成时间：" + timestamp + "）=====\n" +
               "员工姓名：" + name + "\n" +
               "员工工号：" + empId + "\n" +
               "所属部门：" + department + "\n" +
               "入职日期：" + hireDate + "\n" +
               "员工类型：" + this.getClass().getSimpleName() + "\n" +
               "本月薪资：" + String.format("%.2f", salary) + "元\n" +
               "=================";
    }

    public String getName() { return name; }
    public String getEmpId() { return empId; }
}